import { EArenaMode } from "../../../../Message/Public/EArenaMode";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { ArenaCrossGetListData } from "./arenaCrossData/ArenaCrossGetListData";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../resource/ImagesConst";
import { ObjCreate } from "../common/ObjCreate";
import { Language } from "../../../../extend/language/Language";
import { Cache } from "../../cache/Cache";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { ResFileConst } from "../../resource/ResFileConst";
import { SecTimerView } from "../common/SecTimerView";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { ResouceConst } from "../../../component/gconst/ResouceConst";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { ArenaCrossMyBattlesWindow } from "./ArenaCrossMyBattlesWindow";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { ArenaCrossJoinData } from "./arenaCrossData/ArenaCrossJoinData";
import { TitleItem } from "../common/item/TitleItem";
import { ObjTeamCreate } from "../common/ObjTeamCreate";
import { TilePanel } from "../equipment/TilePanel";
import { ArenaCrossTopCellRenderer } from "./cellRenderer/ArenaCrossTopCellRenderer";
import { PageSelecter } from "../common/pageSelect/PageSelecter";
import { SMyArenaCrossInfo } from "../../../../Message/Public/SMyArenaCrossInfo";
import { EArenaProcess } from "../../../../Message/Public/EArenaProcess";
import { SArenaCrossToplists } from "../../../../Message/Public/SArenaCrossToplists";
import { ClockManager } from "../../manager/ClockManager";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { GLoadedButton } from "../../../../com/mui/controls/GLoadedButton";
import { GButton } from "../../../../com/mui/controls/GButton";
type int = number;
//class ArenaCrossMainPanel
    
    export  class ArenaCrossMainPanel /* flash.display.Sprite */
    {
        constructor()
        {
            
            this._currentMode = EArenaMode.convert(EArenaMode._EArenaOneVsOne);
            this._currentMode = EArenaMode.convert(EArenaMode._EArenaOneVsOne);
            this.createChildren();
            return;
        }

        /* internal  */createChildren(): void
        {
            this.createLeftPart();
            this.createRightPart();
            this.addEventListener(flash.events.Event.ADDED_TO_STAGE, this.onAddToStage);
            return;
        }

        /* internal  */onAddToStage(arg1: Object /* flash.events.Event */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.ArenaCrossGetMyArenaInfo));
            return;
        }

        /* internal  */getListData(): void
        {
            if (this._myArenaCrossinfo) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.ArenaCrossGetArenaLists, new ArenaCrossGetListData(this._myArenaCrossinfo.myProcess, this._pageSelecter.currentPage)));
            }
            return;
        }

        /* internal  */onResCompl(): void
        {
            this._bmpBtnBg.bitmapData = GlobalClass.getBitmapData(ImagesConst.ArenaCrossBg);
            this._bmpBtnBg.width = 186;
            this._bmpNotes.bitmapData = GlobalClass.getBitmapData(ImagesConst.ArenaCrossNotes);
            return;
        }

        /* internal  */createLeftPart(): void
        {
            var loc1=null;
            loc1 = new Object /* flash.display.Sprite */();
            loc1.mouseEnabled = false;
            this.addChild(loc1);
            ObjCreate.createBg(0, 0, 193, 483, loc1);
            this._tfName = this.createItemValue(Language.getString(42214), Cache.instance.role.entityInfo.name, 15, 10, 150, 20, loc1);
            this._tfWinPer = this.createItemValue(Language.getString(42220), "0%", 15, 35, 90, 20, loc1);
            this._tfWin = this.createItemValue(Language.getString(42217), "0", 105, 35, 90, 20, loc1);
            this._tfBattleNum = this.createItemValue(Language.getString(44216), "0", 15, 60, 150, 20, loc1);
            this._tfLose = this.createItemValue(Language.getString(42218), "0", 105, 60, 90, 20, loc1);
            this._tfRank = ObjCreate.createTextField("", 15, 85, 190, 20, loc1);
            this._tfRank.htmlText = Language.getStringByParam(44254, Language.getString(42231));
            this._tfCurrentProcess = ObjCreate.createTextField("", 15, 110, 220, 20, loc1, GlobalStyle.textFormat6);
            this._bmpBtnBg = new Object /* flash.display.Bitmap */();
            ObjCreate.setObjAttri(this._bmpBtnBg, 5, 136, -1, -1, loc1);
            this._btnJoin = ObjCreate.createGLoadedButton(ResFileConst.ArenaJoin, 46, 138, 102, 99, loc1);
            this._btnJoin.enabled = true;
            var loc2=GlobalStyle.textFormat6;
            loc2.size = 12;
            loc2.bold = true;
            this._timeView = new SecTimerView();
            this._timeView.mouseEnabled = false;
            ObjCreate.setObjAttri(this._timeView, 40, 245, 200, 20, this);
            this._timeView.defaultTextFormat = loc2;
            this._timeView.filters = [FilterConst.glowFilter];
            this._timeView.setParse(Language.getString(44255));
            this._timeView.visible = false;
            var loc3=ResouceConst.getScaleBitmap("SplitLine");
            ObjCreate.setObjAttri(loc3, 16, 275, 165, 2, loc1);
            loc1.addChild(loc3);
            this._btnJoin.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnJoin);
            this._spLeftBottom = new Object /* flash.display.Sprite */();
            this._spLeftBottom.x = 10;
            this._spLeftBottom.y = 278;
            loc1.addChild(this._spLeftBottom);
            this._bmpNotes = new Object /* flash.display.Bitmap */();
            ObjCreate.setObjAttri(this._bmpNotes, 34, 31, -1, -1, this._spLeftBottom);
            this._tfArenaPeopleNum = ObjCreate.createTextField(Language.getStringByParam(44217, "0"), 32, 72, 140, 20, this._spLeftBottom, GlobalStyle.textFormat6);
            this._tfArenaNumNeed = ObjCreate.createTextField("", 45, 97, 140, 20, this._spLeftBottom, GlobalStyle.textFormat6);
            this._tfArenaNumNeed.htmlText = Language.getStringByParam(44218, "20");
            this._btnMyTodyBattle = ObjCreate.createGButton(Language.getString(44219), 35, 126, 98, 22, this._spLeftBottom);
            this._btnMyTodyBattle.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnMyTodayBattleClick);
            LoaderHelp.addResCallBack(ResFileConst.areanCrossMain, this.onResCompl);
            this.updateWillOpenTime();
            return;
        }

        public getNeedRankByProcess(arg1: int): int
        {
            return 160;
        }

        /* internal  */onBtnMyTodayBattleClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            ArenaCrossMyBattlesWindow.instance.show();
            return;
        }

        /* internal  */createItemValue(arg1: string, arg2: string="", arg3: number=0, arg4: number=0, arg5: number=90, arg6: number=20, arg7: Object /* flash.display.DisplayObjectContainer */=null): Object /* flash.text.TextField */
        {
            var loc1=ObjCreate.createTextField("", arg3, arg4, arg5, arg6, arg7);
            this.updateItemValue(loc1, arg1, arg2);
            return loc1;
        }

        /* internal  */updateItemValue(arg1: Object /* flash.text.TextField */, arg2: string, arg3: string): void
        {
            arg1.htmlText = HTMLUtil.addColor(arg2, "#FFFFFF") + HTMLUtil.addColor(arg3, GlobalStyle.color1);
            return;
        }

        /* internal  */onBtnJoin(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=false;
            if (this._btnJoin.styleName != ResFileConst.ArenaJoin) 
            {
                loc1 = true;
            }
            else 
            {
                loc1 = false;
            }
            var loc2=new ArenaCrossJoinData(loc1, this._currentMode);
            Dispatcher.dispatchEvent(new DataEvent(EventName.ArenaCrossJoin, loc2));
            return;
        }

        /* internal  */createRightPart(): void
        {
            var loc1=new Object /* flash.display.Sprite */();
            loc1.x = 196;
            loc1.mouseEnabled = false;
            this.addChild(loc1);
            ObjCreate.createSpBannerAndBg(0, 0, 607, 449, "", loc1);
            var loc2=new Vector.<TitleItem>();
            loc2.push(new TitleItem(Language.getString(44221), 60));
            loc2.push(new TitleItem(Language.getString(44222), 185));
            loc2.push(new TitleItem(Language.getString(44223), 60));
            loc2.push(new TitleItem(Language.getString(44224), 60));
            loc2.push(new TitleItem(Language.getString(44225), 60));
            loc2.push(new TitleItem(Language.getString(44226), 60));
            loc2.push(new TitleItem(Language.getString(44227), 60));
            loc2.push(new TitleItem(Language.getString(44228), 60));
            var loc3=ObjTeamCreate.createTitles(loc2);
            ObjCreate.setObjAttri(loc3, 0, 7, -1, -1, loc1);
            this._tfNoRecord = ObjCreate.createTextField(Language.getString(44229), 270, 200, 200, 20, loc1, GlobalStyle.textFormat6);
            this._tfNoRecord.visible = true;
            this._arenaTopListPanel = new TilePanel();
            this._arenaTopListPanel.setSize(606, 420);
            this._arenaTopListPanel.rowHeight = 42;
            this._arenaTopListPanel.columnWidth = 606;
            this._arenaTopListPanel.setStyle("cellRenderer", ArenaCrossTopCellRenderer);
            this._arenaTopListPanel.x = 0;
            this._arenaTopListPanel.y = 30;
            this._arenaTopListPanel.visible = false;
            loc1.addChild(this._arenaTopListPanel);
            this._pageSelecter = new PageSelecter();
            this._pageSelecter.mode = PageSelecter.InputMode;
            this._pageSelecter.x = 158;
            this._pageSelecter.y = 458;
            this._pageSelecter.pageTextBoxSize = 50;
            loc1.addChild(this._pageSelecter);
            this._pageSelecter.addEventListener(flash.events.Event.CHANGE, this.onChange);
            return;
        }

        public resetOpenState(arg1: Boolean): void
        {
            return;
        }

        public updateMyArenaInfo(arg1: SMyArenaCrossInfo): void
        {
            this._myArenaCrossinfo = arg1;
            this.updateItemValue(this._tfName, Language.getString(42214), Cache.instance.role.entityInfo.name);
            var loc1=Language.getString(42231);
            if (arg1.rank != 0) 
            {
                loc1 = arg1.rank.toString();
            }
            var loc2=Language.getStringByParam(44254, loc1);
            var loc3;
            if ((loc3 = this.getNeedRankByProcess(this._myArenaCrossinfo.myProcess)) > 0) 
            {
                loc2 = loc2 + Language.getStringByParam(44253, loc3.toString());
            }
            var loc4=Math.floor(arg1.winNum * 100 / (arg1.winNum + arg1.loseNum));
            this.updateItemValue(this._tfWinPer, Language.getString(42220), loc4 + "%");
            this._tfRank.htmlText = loc2;
            this.updateItemValue(this._tfWin, Language.getString(42217), arg1.winNum.toString());
            this.updateItemValue(this._tfLose, Language.getString(42218), arg1.loseNum.toString());
            this.updateItemValue(this._tfBattleNum, Language.getString(44216), (arg1.winNum + arg1.loseNum).toString());
            this._tfCurrentProcess.htmlText = this.getProcessText(arg1.myProcess);
            this._tfArenaPeopleNum.htmlText = Language.getStringByParam(44217, arg1.waitingNum.toString());
            var loc5;
            if ((loc5 = 20 - arg1.winNum - arg1.loseNum) < 0) 
            {
                loc5 = 0;
            }
            this._tfArenaNumNeed.htmlText = Language.getStringByParam(44218, loc5.toString());
            this.getListData();
            return;
        }

        /* internal  */getProcessText(arg1: int): string
        {
            var loc1=Language.getString(44262);
            var loc2=arg1;
            switch (loc2) 
            {
                case EArenaProcess._EArenaElimination1:
                {
                    loc1 = Language.getString(44258);
                    break;
                }
                case EArenaProcess._EArenaElimination2:
                {
                    loc1 = Language.getString(44259);
                    break;
                }
                case EArenaProcess._EArenaElimination3:
                {
                    loc1 = Language.getString(44260);
                    break;
                }
                case EArenaProcess._EArenaElimination4:
                {
                    loc1 = Language.getString(44261);
                    break;
                }
            }
            return loc1;
        }

        public updateSignUpState(arg1: Boolean): void
        {
            if (arg1) 
            {
                this._btnJoin.styleName = ResFileConst.ArenaCancelJoin;
            }
            else 
            {
                this._btnJoin.styleName = ResFileConst.ArenaJoin;
            }
            return;
        }

        /* internal  */onChange(arg1: Object /* flash.events.Event */): void
        {
            this.getListData();
            return;
        }

        public updateArenaCrossTopData(arg1: SArenaCrossToplists): void
        {
            this._arenaCrossTopList = arg1;
            this._pageSelecter.maxPage = arg1.pageNum;
            this.updateList();
            this.updateVisible();
            return;
        }

        public get process(): int
        {
            if (this._myArenaCrossinfo) 
            {
                return this._myArenaCrossinfo.myProcess;
            }
            return -1;
        }

        public updateWillOpenTime(): void
        {
            if (Cache.instance.arenaCross.isWillOpen) 
            {
                this._timeView.visible = true;
                this._timeView.setLeftTime(Math.ceil((Cache.instance.arenaCross.willOpen.openDt.time - ClockManager.instance.nowDate.time) / 1000));
            }
            else if (this._timeView) 
            {
                this._timeView.visible = false;
                this._timeView.stop();
            }
            return;
        }

        /* internal  */updateList(): void
        {
            this._arenaTopListPanel.dataProvider = new DataProvider(this._arenaCrossTopList.toplists);
            return;
        }

        /* internal  */updateVisible(): void
        {
            var loc1=this._arenaCrossTopList && this._arenaCrossTopList.toplists.length > 0;
            this._arenaTopListPanel.visible = loc1;
            this._tfNoRecord.visible = !loc1;
            return;
        }

        /* internal */ /* const */pageSize: int=10;

        /* internal */ /* var */_arenaCrossTopList: SArenaCrossToplists;

        /* internal */ /* var */_myArenaCrossinfo: SMyArenaCrossInfo;

        /* internal */ /* var */_tfName: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfRank: Object /* flash.text.TextField */;

        /* internal */ /* var */_pageSelecter: PageSelecter;

        /* internal */ /* var */_tfWin: Object /* flash.text.TextField */;

        /* internal */ /* var */_currentMode: EArenaMode;

        /* internal */ /* var */_tfLose: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfBattleNum: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfCurrentProcess: Object /* flash.text.TextField */;

        /* internal */ /* var */_bmpBtnBg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_btnJoin: GLoadedButton;

        /* internal */ /* var */_timeView: SecTimerView;

        /* internal */ /* var */_spLeftBottom: Object /* flash.display.Sprite */;

        /* internal */ /* var */_bmpNotes: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_tfArenaPeopleNum: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfArenaNumNeed: Object /* flash.text.TextField */;

        /* internal */ /* var */_btnMyTodyBattle: GButton;

        /* internal */ /* var */_btnMyPosition: GButton;

        /* internal */ /* var */_tfNoRecord: Object /* flash.text.TextField */;

        /* internal */ /* var */_arenaTopListPanel: TilePanel;

        /* internal */ /* var */_tfWinPer: Object /* flash.text.TextField */;
    }
